﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Artech.PetShop.Orders.BusinessEntity;
using Artech.PetShop.Common;
using Artech.PetShop.Orders;

namespace PetShop
{
    public partial class _Default : ViewBase<ProductsPresenter>, IProductsView
    {
        protected override void OnError(EventArgs e)
        {
            base.OnError(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Presenter = new ProductsPresenter(this);
            this.Presenter.ListAllProducts();
        }

        #region IProductsView Members

        public void BindAllProducts(Product[] products)
        {
            this.DataListProducts.DataSource = products;
            this.DataListProducts.DataBind();
        }        
         
        #endregion

        protected void DataListProducts_ItemCommand(object source, DataListCommandEventArgs e)
        {
            Label productIDLabel = e.Item.FindControl("LabelProductID") as Label;
            if (productIDLabel == null)
            {
                return;
            }

            this.Presenter.AddProductInShopCart(new Guid(productIDLabel.Text));      
        }
    }
}
